import request from '@/utils/request';

export function getIngredientsByDishId(dish_id) {
    return request({
        url: `/ingredients/${dish_id}/ingredients`,
        method: 'get'
    });
}

export function getAllIngredients() {
    return request({
        url: '/ingredients/getAllIngredients',
        method: 'get'
    });
}

export function getAllDeletedIngredients() {
    return request({
        url: '/ingredients/getAllDeletedIngredients',
        method: 'get'
    });
}

export function addNewIngredient(ingredientData) {
    return request({
        url: '/ingredients/addIngredient',
        method: 'post',
        data: ingredientData // 传递FormData对象
    });
}

export function updateIngredient(ingredient_id, updatedData) {
    return request({
        url: `/ingredients/updateIngredient`, // 确保与后端路由一致
        method: 'put',
        data: { ingredient_id, ...updatedData }
    });
}

//添加菜品和原料的关联
export function addDishIngredient(dish_id, ingredient_id) {
    return request({
        url: `/ingredients/addDishIngredient`, // 确保与后端路由一致
        method: 'post',
        data: {dish_id, ingredient_id}
    });
}

//删除菜品和原料的关联
export function deleteDishIngredient(dish_id, ingredient_id) {
    return request({
        url: `/ingredients/delete/${dish_id}/${ingredient_id}`,
        method: 'delete'
    });
}

